package com.hjh.gameforum.controller;

import com.hjh.gameforum.result.Result;
import com.hjh.gameforum.service.ReplyService;
import com.hjh.gameforum.service.TopicService;
import com.hjh.gameforum.service.UserService;
import com.hjh.gameforum.vo.TopicVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/statistics")
@RequiredArgsConstructor
@Tag(name = "统计相关接口", description = "统计相关接口")  // 替换原来的 @Api
@Slf4j
public class StatisticsController {

    // 使用构造器注入替代@Autowired
    private final UserService userService;
    private final TopicService topicService;
    private final ReplyService replyService;

    @GetMapping("/users")
    @Operation(summary = "新增用户统计", description = "获取新增用户统计数据")
    public Result getUserStats(@RequestParam String unit) {
        Map<String, Object> data = userService.getUserStats(unit);
        return Result.success(data);
    }

    @GetMapping("/active-users")
    @Operation(summary = "活跃用户统计", description = "获取近7天登录过的用户数")
    public Result getActiveUserStats() {
        log.info("获取近7天登录过的用户数");
        Map<String, Object> data =userService.getActiveUserStats();
        return Result.success(data);
    }

    @GetMapping("/total-users")
    @Operation(summary = "用户总数统计", description = "获取用户总数统计数据")
    public Result getTotalUserStats() {
        log.info("获取用户总数统计数据");
        Long data = userService.getTotalUsers();
        return Result.success(data);
    }

    @GetMapping("/top-topics")
    @Operation(summary = "话题排行榜", description = "根据浏览或者点赞获取话题排行榜")
    public Result getLikeTopicStats(@RequestParam String unit) {
        log.info("获取话题排行榜");
        List<TopicVo> topics = topicService.getTopicTop(unit);
        return Result.success(topics);
    }

    @GetMapping("/topics")
    @Operation(summary = "话题数量统计", description = "获取话题数量统计数据")
    public Result getTopicCountStats(@RequestParam String unit) {
        log.info("获取话题数量统计数据");
        Map<String, Object> data = topicService.getTopicCountStats(unit);
        return Result.success(data);
    }

    @GetMapping("/total-topics")
    @Operation(summary = "话题总数统计", description = "获取话题总数统计数据")
    public Result getTotalTopicStats() {
        log.info("获取话题总数统计数据");
        Long data = topicService.getTotalTopics();
        return Result.success(data);
    }

    @GetMapping("/total-replies")
    @Operation(summary = "回复总数统计", description = "获取回复总数统计数据")
    public Result getTotalReplyStats() {
        log.info("获取回复总数统计数据");
        Long data = replyService.getTotalReplys();
        return Result.success(data);
    }




}